const http = require('http')
const https = require('https')

const server = http.createServer((request, response) => {
  console.log(request);
  response.writeHeader(200, {
    'content-type': 'application/json;charset=utf-8',
    'Access-Control-Allow-Origin': '*'
  })
  let data = ''
  https.get('https://www.xiaomiyoupin.com/mtop/mf/resource/data/list', (res) => {
    res.on('data', (chunk) => {
      data += chunk
    })
    res.on('end', () => {
      response.writeHead(200, {
        'content-type': 'application/json;charset=utf-8'
      })
      response.end(data)
    })
  })
})

server.listen(8080, () => {
  console.log('http://localhost:8080/');
})
